﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace ProjectStudy.App_Code
{
    public class JSFunction : System.Web.UI.Page
    {
        /// <summary>
        /// 后台alert弹窗
        /// </summary>
        /// <param name="page">弹窗页面</param>
        /// <param name="msg">弹窗内容</param>
        public static void Alert(Page page,string msg)
        {
            page.ClientScript.RegisterStartupScript(page.ClientScript.GetType(), "1", "<script language='javascript' type='text/javascript'>alert('"+msg+"');</script>");           
        }
        public static void Confirm(Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.ClientScript.GetType(), "2", "<script language='javascript' type='text/javascript'>confirm('" + msg + "');</script>");
        }

        /// <summary>
        /// 调用前台js无参方法
        /// </summary>
        /// <param name="page">调用页面</param>
        /// <param name="functionName">前台js方法名</param>
        public static void CallJsFunction(Page page, string functionName)
        {
            page.ClientScript.RegisterStartupScript(page.ClientScript.GetType(), "3", "<script language='javascript' type='text/javascript'>" + functionName + "();</script>");
        }

        /// <summary>
        /// 调用前台js有参方法
        /// </summary>
        /// <param name="page">调用页面</param>
        /// <param name="functionName">方法名</param>
        /// <param name="ps">参数列表</param>
        public static void CallJsFunction(Page page, string functionName, string[] ps)
        {
            page.ClientScript.RegisterStartupScript(page.ClientScript.GetType(), "4", "<script language='javascript' type='text/javascript'>" + functionName+"("+ps+");</script>");
        }
    }
}